//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.api.domain.ExcelDownloadLog;
import com.ruoyi.system.service.IExcelDownloadLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping({"/log"})
public class ExcelDownloadLogController extends BaseController {
    @Autowired
    private IExcelDownloadLogService excelDownloadLogService;

    @GetMapping({"/list"})
    public TableDataInfo list(ExcelDownloadLog excelDownloadLog) {
        this.startPage();
        List<ExcelDownloadLog> list = this.excelDownloadLogService.selectExcelDownloadLogList(excelDownloadLog);
        return this.getDataTable(list);
    }

    @Log(
            title = "日志Excel导出信息",
            businessType = BusinessType.INSERT
    )
    @PostMapping({"/insert"})
    public AjaxResult insert(@RequestBody ExcelDownloadLog excelDownloadLog) {
        return this.toAjax(this.excelDownloadLogService.insertExcelDownloadLog(excelDownloadLog));
    }

    @Log(
            title = "日志Excel导出信息",
            businessType = BusinessType.EXPORT
    )
    @PostMapping({"/export"})
    public void export(HttpServletResponse response, ExcelDownloadLog excelDownloadLog) throws IOException {
        List<ExcelDownloadLog> list = this.excelDownloadLogService.selectExcelDownloadLogList(excelDownloadLog);
        ExcelUtil<ExcelDownloadLog> util = new ExcelUtil(ExcelDownloadLog.class);
        util.exportExcel(response, list, "log");
    }

    @GetMapping({"/{appleId}"})
    public AjaxResult getInfo(@PathVariable("appleId") Long appleId) {
        return AjaxResult.success(this.excelDownloadLogService.selectExcelDownloadLogById(appleId));
    }

    @Log(
            title = "日志Excel导出信息",
            businessType = BusinessType.UPDATE
    )
    @PostMapping({"/edit"})
    public AjaxResult edit(@RequestBody ExcelDownloadLog excelDownloadLog) {
        return this.toAjax(this.excelDownloadLogService.updateExcelDownloadLog(excelDownloadLog));
    }

    @Log(
            title = "日志Excel导出信息",
            businessType = BusinessType.DELETE
    )
    @DeleteMapping({"/{appleIds}"})
    public AjaxResult remove(@PathVariable Long[] appleIds) {
        return this.toAjax(this.excelDownloadLogService.deleteExcelDownloadLogByIds(appleIds));
    }
}
